#include <algorithm>
#include <iostream>
using namespace std;

const int kN = 12;
const int kInf = 1e9;

int s[4], cnt[4];
int lv[kN];
int ans = kInf;

void DFS(int dep) {
  if (dep == kN) {
    int mins = s[0], maxs = s[0];

    for (int i = 1; i < 4; i++) {
      mins = min(mins, s[i]);
      maxs = max(maxs, s[i]);
    }
    ans = min(ans, maxs - mins);
    return;
  }
  for (int i = 0; i < 4; i++) {
    if (cnt[i] < 3) {
      s[i] += lv[dep];
      cnt[i]++;
      DFS(dep + 1);
      s[i] -= lv[dep];
      cnt[i]--;
    }
  }
}

int main() {
  freopen("bteams.in", "r", stdin);
  freopen("bteams.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  for (int i = 0; i < kN; i++) {
    cin >> lv[i];
  }
  s[0] = lv[0], cnt[0] = 1;
  DFS(1);
  cout << ans << "\n";
  return 0;
}